#pragma once
#include "Red.h"
#include "HPath.h"
#include <set>

using namespace std;

struct hpath_compare {

	bool operator()(const HPath& h1, const HPath& h2) const {
		return h1.getCosto() < h2.getCosto();
	}
};

class ConstructionPhase
{
public:

	ConstructionPhase(Red * g, int lSize) : grafo(g), listSize(lSize) {};

	Red * ejecutar();

	~ConstructionPhase(void);

private:
	Red * grafo;
	int listSize;

	InfoVertice selectRandomTerminal();
	void initTerminalesFaltantes(set<int> &faltantes);
	void agregarNuevoTerminal(Red * gSol, InfoVertice &s, set<int> &terminalesAgregados, set<int> &terminalesFaltantes);
	
	void construirCaminosMasCortos(Red * gSol, set<int> &terminalesFaltantes, vector<HPath> &rcl);
	void construirKeyPathMinimo(Red * gSol, InfoVertice & terminal, Path &p1, Path &p2);
	void obtenerNodosUsados(Red * gSol, Path &p, InfoVerticeSet& nodosUsados);

	HPath selectRandomHPath(vector<HPath> &rcl);
	void agregarCaminos(Red * gSol, HPath &hPath);
	void eliminarKeyPathRedundante(Red * gSol, HPath &hPath);
	void actualizarTerminalesAgregados(set<int> &terminalesActuales, set<int> &terminalesFaltantes, HPath &hPath);
};
